package com.seanLab.dto.FeedbackDto;

import com.seanLab.domain.EditorAddTag;
import com.seanLab.domain.EditorDeleteTag;
import com.seanLab.domain.EditorFeedback;
import com.seanLab.domain.EditorImageScore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * Created by ailly on 17-10-6.
 */
public class FeedbackDto2Domain {

    public static HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

    public static EditorFeedback transferEditorFeedback(EditorFeedbackDto editorFeedbackDto) {
        EditorFeedback tmpEditorFeedback = new EditorFeedback();

        tmpEditorFeedback.setFeedbackID("feedbackID-" + UUID.randomUUID().toString());
        tmpEditorFeedback.setSessionID(editorFeedbackDto.getSessionID());
        tmpEditorFeedback.setAdoptedImgs(editorFeedbackDto.getAdoptedImgs());
        tmpEditorFeedback.setFeedbackDate(new Date());
        tmpEditorFeedback.setFeekbackIPAddr(request.getRemoteAddr());
        tmpEditorFeedback.setAcceptFlag(editorFeedbackDto.getAcceptFlag());
        tmpEditorFeedback.setIsTestFlag(editorFeedbackDto.getIsTestFlag());
        tmpEditorFeedback.setArticleCategory(editorFeedbackDto.getArticleCategory());

        return  tmpEditorFeedback;
    }

    public static EditorAddTag transferEditorAddTag (EditorAddTagDto editorAddTagDto) {
        EditorAddTag tmpEditorAddTag = new EditorAddTag();

        tmpEditorAddTag.setAddTagID("addTagID-" + UUID.randomUUID().toString());
        tmpEditorAddTag.setSessionID(editorAddTagDto.getSessionID());
        //tmpEditorAddTag.setAddTagDate(new Date());
        tmpEditorAddTag.setImgID(editorAddTagDto.getImgID());
        tmpEditorAddTag.setNewTagName(editorAddTagDto.getNewTags());
        tmpEditorAddTag.setUpdateFlag(0);       //0 表示该反馈还未处理

        return tmpEditorAddTag;
    }

    public static EditorDeleteTag transferEditorDeleteTag (EditorDeleteTagDto editorDeleteTagDto) {
        EditorDeleteTag tmpEditorDeleteTag = new EditorDeleteTag();

        tmpEditorDeleteTag.setDeleteTagID("deleteTagID-" + UUID.randomUUID().toString());
        tmpEditorDeleteTag.setSessionID(editorDeleteTagDto.getSessionID());
        tmpEditorDeleteTag.setDeleteTagDate(new Date());
        tmpEditorDeleteTag.setImgID(editorDeleteTagDto.getImgID());
        tmpEditorDeleteTag.setTagID(editorDeleteTagDto.getTagID());
        tmpEditorDeleteTag.setUpdateFlag(0);    //0 表示该反馈还未处理

        return tmpEditorDeleteTag;
    }

    public static List<EditorImageScore> transferEditorImageScore (EditorImageScoreDto editorImageScoreDto) {
        List<EditorImageScore> tmpEditorImageScoreList = new ArrayList<>();

        String sessionID = editorImageScoreDto.getSessionID();
        for (EditorScoreSingleImgDto e : editorImageScoreDto.getImgScoreList()) {
            EditorImageScore editorImageScore = new EditorImageScore();
            editorImageScore.setImageScoreID("imageScoreID-" + UUID.randomUUID().toString());
            editorImageScore.setSessionID(sessionID);
            editorImageScore.setImgID(e.getImgID());
            editorImageScore.setImgScoreDate(new Date());
            editorImageScore.setImgScoreIPAddr(request.getRemoteAddr());
            editorImageScore.setScore(e.getScore());
            editorImageScore.setReason(e.getReason());
            tmpEditorImageScoreList.add(editorImageScore);
        }

        return  tmpEditorImageScoreList;
    }
}
